package metaRobot;

import robocode.*;
import robocode.util.Utils;
import java.awt.Color;
import java.awt.geom.Point2D;
		
public class Robot_149_26 extends ACRobot
{
	private Point2D.Double _enemyLocation;
	
	public void run() 
	{
		setColors(Color.black, Color.green, Color.yellow, Color.green, Color.red);
		setAdjustRadarForGunTurn(true);	
		while(true) 
		{
						move(false, 50, true, 45);
			move(false, 50, true, 45);
			move(false, 50, true, 45);
			move(false, 50, true, 45);
			move(false, 50, true, 45);
			move(false, 50, true, 45);
			moveToEnemy(_enemyLocation);
			setTurnRadarRight(360);

			
			execute();
		}
	}
	
	public void onScannedRobot(ScannedRobotEvent e) 
	{
		// aggiorna la posizione del nemico
		double absBearing = e.getBearingRadians() + getHeadingRadians();
		_enemyLocation = project(new Point2D.Double(getX(), getY()), absBearing, e.getDistance());
		
		setFire(3);
		if (e.getEnergy() < 10) { 
			if (e.getEnergy() < 10) { 
				if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
					if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
						noOperation();
					} 
					else { 
						turnGunToEnemy(_enemyLocation);
					}
				} 
				else { 
					if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
						noOperation();
					} 
					else { 
						turnGunToEnemy(_enemyLocation);
					}
				}
			} 
			else { 
				if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
					setFire(3);
					if (testEnemyWithinTicksOfFire(e, 10, 1)) { 
						noOperation();
					} 
					else { 
						turnGunToEnemy(_enemyLocation);
					}
				} 
				else { 
					if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
						if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
							noOperation();
						} 
						else { 
							turnGunToEnemy(_enemyLocation);
						}
					} 
					else { 
						if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
							if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
								noOperation();
							} 
							else { 
								turnGunToEnemy(_enemyLocation);
							}
						} 
						else { 
							if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
								turnGunToEnemy(_enemyLocation);
							} 
							else { 
								turnGunRight(10);
							}
						}
					}
				}
			}
		} 
		else { 
			setFire(3);
			if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
				if (testEnemyWithinTicksOfFire(e, 50, 1)) { 
					if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
						if (testEnemyWithinTicksOfFire(e, 10, 1)) { 
							noOperation();
						} 
						else { 
							turnGunToEnemy(_enemyLocation);
						}
					} 
					else { 
						if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
							noOperation();
						} 
						else { 
							turnGunToEnemy(_enemyLocation);
						}
					}
				} 
				else { 
					turnGunRight(10);
				}
			} 
			else { 
				if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
					if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
						if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
							noOperation();
						} 
						else { 
							turnGunToEnemy(_enemyLocation);
						}
					} 
					else { 
						if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
							noOperation();
						} 
						else { 
							turnGunToEnemy(_enemyLocation);
						}
					}
				} 
				else { 
					setFire(3);
					if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
						noOperation();
					} 
					else { 
						turnGunToEnemy(_enemyLocation);
					}
				}
			}
		}


		execute();
	}
	
	public void onHitByBullet(HitByBulletEvent e) 
	{
		move(true, 50, false, 10);


		execute();
	}

	public void onHitWall(HitWallEvent e) 
	{
		if (testEnemyWithinTicks(_enemyLocation, 20)) { 
			moveToCenter();
		} 
		else { 
			if (testEnemyWithinTicks(_enemyLocation, 20)) { 
				moveToCenter();
			} 
			else { 
				if (testEnemyWithinTicks(_enemyLocation, 30)) { 
					moveToCenter();
				} 
				else { 
					moveToCenter();
				}
			}
		}


		execute();
	}
	
	public void onHitRobot(HitRobotEvent e) 
	{
		if (e.getEnergy() < 0.05) { 
			if (e.getEnergy() < 0.05) { 
				if (e.getEnergy() < 10) { 
					setFire(3);
				} 
				else { 
					setFire(3);
				}
			} 
			else { 
				setFire(3);
			}
		} 
		else { 
			setFire(3);
		}


		execute();
	}
}